<template>
  <div class="components-container">
    <div class="header-form">
       <div class="layui-inline" >
            <label class="layui-form-label">接尸日期</label>
            <div class="layui-inline" >
             <el-radio-group v-model="selectDataEixend.regDateValue" @change="getData">
              <el-radio-button  :label="DateSelectMode.now" class="radio">当日</el-radio-button>
              <el-radio-button  :label="DateSelectMode.tomorrow" class="radio">明日</el-radio-button>
              <el-radio-button  :label="DateSelectMode.future" class="radio">以后</el-radio-button>
              <el-radio-button  :label="DateSelectMode.all" class="radio">全部</el-radio-button>
             </el-radio-group>
            </div>
       </div>
    </div>
    <div>
      <ul class="toolList">
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
      </ul>
    </div>

    <dataTable  :headList="headList" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
    <mainmodel ref="models"  @refreshData="getData"></mainmodel>
    <printmodal ref="printPdf"></printmodal>
  </div>
</template>

<script>
import apiBase from "@/api/apiBase.js";

import dataTable from "@/components/Table/DataTable";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
import { DATESELECTMODE } from "@/const/const.js";
import mainmodel from "./roomReservationMain";
import printmodal from "@/components/Pdf/Print";
import { PRINT } from "@/components/Pdf/PDF.js";
import { PRPORDER } from "@/const/orderConst.js";

export default {
  name: "phoneAppointment",
  mixins: [manage],
  data() {
    return {
      DateSelectMode: DATESELECTMODE,
      //编码
      carLics: [],
      drivers: [],
      preSitDesc: null,
      reserveType: [],
      reserveStatus: [],
      serviceListType: [],
      sexType: [],
      ServiceItemsList: [],
      checkedItem: [],
      selectData: {
        TypeEquals: null,
        LinkManLike: null,
        DeadNameLike: null,
        StatusEquals: null,
        WorkDateEquals: null,
        WorkDateGreateAndEquals: null
      },
      selectDataEixend: {
        regDateValue: null
      },
      prpData: {
        PRPID: null,
        PRPNO: null,
        PRPLINKMAN: null,
        PRPLINKPHONE: null,
        PRPORIGINALCALL: null,
        PRPCALLDATE: null,
        PRPDEADNAME: null,
        PRPYITIQX: null,
        PRPDESCRIBE: "",
        PRPCORPSEADDRESS: null,
        PRPWORKDATE: null,
        //服务项目预约信息
        Psts: [],
        //派车信息
        Cdh: {
          CDHCARID: null,
          CARLIC: null,
          CARCODNAME: null,
          CARCODNAMEDESC: null,
          CDHDRIVER: null,
          STANAME: null
        }
      },
      cdhcar: ["", ""],
      carType: null
    };
  },
  methods: {
    //获取电话预约数据
    getData() {
      let data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: JSON.parse(JSON.stringify(this.selectData))
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Reserve.QueryPhoneReserve,
        res => {
          this.dataList = res.data.content.OutData;
          this.pageOrder.totalNum = res.data.content.RecordCount;
          this.dataList.forEach(data => {
            data.PRPWORKDATE = data.PRPWORKDATE.substring(0, 16);
          });
        }
      );
    },
    //获取表头
    getColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetPhoneReserveColumns,
        res => {
          this.headList = res.data.content;
        }
      );
    },

    //功能操作
    operate(order) {
      this.order = order;
      this.dataRepeat();
      switch (this.order) {
        case PRPORDER.ADD:
          this.$refs.models.open(this.order);
          break;
        case PRPORDER.MODIFY:
          this.$refs.models.open(this.order, this.currentRow.PRPID);
          break;
        case PRPORDER.DELETE:
          this.confirm(callback => {
            this.dataDelete();
          });
          break;
        case PRPORDER.INFO:
          this.$refs.models.open(this.order, this.currentRow.PRPID);
          break;
        case PRINT.PRINTSEND://打印派车单
          this.$refs.printPdf.open(this.order, this.currentRow.PRPID, null);
          break;
        case PRINT.PHONERECORDER:
          this.$refs.printPdf.open(this.order);
          break;
        case PRINT.PDFDEADLABEL:
          this.$refs.printPdf.open(this.order, this.currentRow.PRPID);
          break;
        case PRINT.PDFFLOWSHEET:
          this.$refs.printPdf.open(this.order, this.currentRow.PRPID);
          break;
        default:
      }
    },
    //提交
    submit() {
      switch (this.order) {
        case ADD:
          this.dataAdd();

          break;
        case MODIFY:
          this.dataModify();

          break;
        case DELETE:
          break;
        case INFO:
          this.$refs.dialog.close();
          break;
        default:
      }
    },
    //数据重置
    dataRepeat() {
      this.pcrFirst = false;
      this.preFirst = false;
      this.checkedItem = [];
      this.cdhcar = ["", ""];
      Object.assign(this.$data.prpData, this.$options.data().prpData);
    },
    //登记删除
    dataDelete() {
      let Data = {
        PRPID: this.currentRow.PRPID
      };
      apiBase.DoService(
        Data,
        apiBase.getApiAdress().Reserve.DeletePhoneReserve,
        res => {
          this.getData();
        }
      );
    },

    //获取预约类型
    getReserveType() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Code.GetReserveType,
        res => {
          this.reserveType = res.data.content;
        }
      );
    },
    //获取预约状态
    getReserveStatus() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Reserve.GetReserveStatus,
        res => {
          this.reserveStatus = res.data.content;
        }
      );
    },
    //获取遗体去向
    getServiceTypes() {
      let data = {};
      apiBase.DoService(data, apiBase.getApiAdress().Code.GetYitiqx, res => {
        this.serviceListType = res.data.content;
      });
    },
    //获取性别
    getSexType() {
      let data = {};
      apiBase.DoService(data, apiBase.getApiAdress().Code.GetSex, res => {
        this.sexType = res.data.content;
      });
    },
    //获取服务项目
    getServiceItems() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Reserve.QueryServiceItem,
        res => {
          let serviceList = res.data.content;
          for (var i in serviceList) {
            this.ServiceItemsList.push.apply(
              this.ServiceItemsList,
              serviceList[i].Sits
            );
          }
        }
      );
    },
    //获取车辆信息
    getCar() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Car.QueryCarByType,
        res => {
          let cardata = res.data.content;
          var car = {
            CodeName: "自送",
            CodeValue: "",
            list_Cars: [
              {
                CARLIC: "自送",
                CARID: ""
              }
            ]
          };
          cardata.splice(0, 0, car);

          let legendsCarData = cardata.map(item => ({
            label: item.CodeName,
            value: item.CodeValue,
            children: item.list_Cars.map(caritem => ({
              label: caritem.CARLIC,
              value: caritem.CARID
            }))
          }));

          this.carLics = legendsCarData;
        }
      );
    },
    //获取司机
    getDrivers() {
      let data = {};
      apiBase.DoService(data, apiBase.getApiAdress().Staff.QueryDriver, res => {
        let driverData = res.data.content,
          legendsDrivers = driverData.map(item => ({
            label: item.STANAME,
            value: item.STAID
          }));
        this.drivers = legendsDrivers;
      });
    },

    //服务项目选择
    ServiceItemsChange(serItems) {
      let pstsList = [];
      for (var i in serItems) {
        var pst = {
          PSTSITID: serItems[i],
          PSTNUMBER: 1
        };
        this.preSitDesc += pstsList.push(pst);
      }
      this.prpData.Psts = pstsList;
    },
    //服务项目选择
    changItem(el, val) {
      var staname = val.SITNAME + "。";
      if (el.target.checked) this.prpData.PRPDESCRIBE += staname;
      else
        this.prpData.PRPDESCRIBE = this.prpData.PRPDESCRIBE.replace(
          staname,
          ""
        );
    },

    initSeachdata() {
      this.selectDataEixend.regDateValue = DATESELECTMODE.now;
      this.selectData.WorkDateEquals = formatDate(new Date(), "yyyyMMdd");
    }
  },

  components: {
    //  sweetModal,
    dataTable,
    mainmodel,
    printmodal
  },
  mounted() {
    this.initSeachdata();
  },
  activated() {
    this.getData();
  },
  created() {
    //this.getData();
    this.getColumns();
    this.getReserveType();
    this.getReserveStatus();
    this.getServiceTypes();
    this.getServiceItems();
    this.getSexType();
    this.getCar();
    this.getDrivers();
    // console.log("btns", this.$store.state.btnListCommon);
  },
  watch: {
    "selectDataEixend.regDateValue": function(val) {
      this.selectData.WorkDateGreate = null;
      this.selectData.WorkDateEquals = null;
      switch (val) {
        case DATESELECTMODE.now:
          this.selectData.WorkDateEquals = formatDate(new Date(), "yyyyMMdd");
          break;
        case DATESELECTMODE.tomorrow:
          var day = new Date();
          day.setDate(day.getDate() + 1);
          this.selectData.WorkDateEquals = formatDate(day, "yyyyMMdd");
          break;
        case DATESELECTMODE.future:
          this.selectData.WorkDateGreate = formatDate(new Date(), "yyyyMMdd");
          break;
        default:
          break;
      }
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
.sw-table {
  width: 600px;
}
.sw-table-lable {
  width: 100px;
}
.sw-table-input {
  width: 200px;
}
.sweet-content-content {
  width: 100%;
}
</style>